/*
 * @Author: Jim <jimjiang0909@gmail.com>
 * @Create time:   2016-09-06 10:02:14
 * @Last Modified by:   Jim
 * @Last Modified time: 2016-09-06 10:03:41
 * @File Name: myProfileInfo.js
 */

define(function(require, exports, module) {

    var tpl = require('{base}/tpls/myProfileInfo.tpl');

    var myProfileInfo = {

        template: _.template(tpl),

        render: function(page, obj) {
            this.page = page;
            this.getAjaxStatus();
            return this.template(this.getTplData());
        },

        componentMount: function() {
            $('#' + this.page.id).find('.myProfileInfo').imglazyload();
        },

        componentUpdate: function() {
            $('#' + this.page.id).find('.myProfileInfo').replaceWith(this.template(this.getTplData()));
            this.componentMount();
        },

        getTplData: function() {
            var userInfo = JSON.parse(Util.getSessionStorage('userInfo')),
                userStatus = JSON.parse(Util.getSessionStorage('userStatus'));
            //console.log(38,userInfo, userStatus);

            var tplObj = {
                avatar: '',
                hidden: '',
                viewedNew: '',
                viewedTotal: '',
                interested: '',
                photo_verify: '',
            };

            if (typeof(userInfo) != 'undefined' && userInfo != null) {
                tplObj.avatar = userInfo.photo.picture;
                tplObj.hidden = userInfo.account.hidden;
                tplObj.photo_verify = userInfo.status.photo_verify;
            }
            if (typeof(userStatus) != 'undefined' && userStatus != null) {
                tplObj.viewedNew = userStatus.viewed_count.new_count;
                tplObj.viewedTotal = userStatus.viewed_count.total;
                tplObj.interested = userStatus.interested_count.new_count;
                tplObj.photoLiked = userStatus.photo_likes_count.new_count;
            }
            //console.log(tplObj);
            return tplObj;
        },

        getAjaxStatus: function() {
            var tthis = this,
                callback = function(data) {
                    tthis.componentUpdate();
                }
            Share.getUserStatus(callback);
        }
    }

    module.exports = myProfileInfo;
});
